<?php
/***
* @version $Id: admin_config.php 336 2007-01-23 08:12:56Z flexiondotorg $
* @copyright (c) 2006 - 2007 Flexion.Org
*            (c) 2004 - 2005 Project Minerva
*            (c) 2001 - 2006 phpBB Group
* @license   http://opensource.org/licenses/gpl-license.php GNU Public License
***/

define('IN_R3BORN', true);

if( !empty($setmodules) )
{
	$module['Anti_spam']['Configuration'] = basename(__FILE__);
	return;
}

$root_path = "./../";
$phpEx = substr(strrchr(__FILE__, '.'),	1);
require('./pagestart.' . $phpEx);
include_once($root_path . 'includes/class_akismet.'.$phpEx);

//
// Pull all config data
//
$sql = "SELECT *
	FROM " . CONFIG_TABLE;
if(!$result = $db->sql_query($sql))
{
	message_die(CRITICAL_ERROR, "Could not query config information in admin_config", "", __LINE__, __FILE__, $sql);
}
else
{
	while( $row = $db->sql_fetchrow($result) )
	{
		$config_name = $row['config_name'];
		$config_value = $row['config_value'];
		$default_config[$config_name] = isset($_POST['submit']) ? str_replace("'", "\'", $config_value) : $config_value;

		$new[$config_name] = ( isset($_POST[$config_name]) ) ? $_POST[$config_name] : $default_config[$config_name];

		if( isset($_POST['submit']) )
		{
			$sql = "UPDATE " . CONFIG_TABLE . " SET
				config_value = '" . str_replace("\'", "''", $new[$config_name]) . "'
				WHERE config_name = '$config_name'";
			if( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, "Failed to update general configuration for $config_name", "", __LINE__, __FILE__, $sql);
			}
		}
	}

	if( isset($_POST['submit']) )
	{
		$message = $lang['Config_updated'] . "<br /><br />" . sprintf($lang['Click_return_antispam'], "<a href=\"" . append_sid("admin_antispam.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");

		message_die(GENERAL_MESSAGE, $message);
	}
}

$confirm_yes = ($new['enable_confirm']) ? 'checked="checked"' : '';
$confirm_no = (!$new['enable_confirm']) ? 'checked="checked"' : '';

$complex_confirm_yes = ($new['complex_confirm']) ? 'checked="checked"' : '';
$complex_confirm_no = (!$new['complex_confirm']) ? 'checked="checked"' : '';

$akismet_enable_yes = ( $new['akismet_enable'] ) ? 'checked="checked"' : '';
$akismet_enable_no = ( !$new['akismet_enable'] ) ? 'checked="checked"' : '';

$akismet_key_valid = $lang['akismet_no_api_key'];

if ( $new['akismet_enable'] && $new['akismet_key'] )
{
	$akismet = new Akismet(generate_website_url(), $new['akismet_key'], array());

	$akismet_key_valid = ( !$akismet->_isValidApiKey($new['akismet_key']) ) ? $lang['akismet_key_invalid'] . '<br />' . $lang['akismet_no_api_key'] : $lang['akismet_key_valid'];
	unset($akismet);
}

$template->set_filenames(array(
	'body' => 'antispam_config_body.tpl')
);

$template->assign_vars(array(
	"S_CONFIG_ACTION" => append_sid("admin_antispam.$phpEx"),
	'L_ANTI_SPAM' => $lang['Anti_spam'],
	'L_ANTI_SPAM_EXPLAIN' => $lang['Anti_spam_explain'],

	"L_GENERAL_SETTINGS" => $lang['General_settings'],

	"L_VISUAL_CONFIRM" => $lang['Visual_confirm'],
	"L_VISUAL_CONFIRM_EXPLAIN" => $lang['Visual_confirm_explain'],
	"L_VISUAL_CONFIRM_COMPLEX" => $lang['Visual_confirm_complex'],
	"L_VISUAL_CONFIRM_COMPLEX_EXPLAIN" => $lang['Visual_confirm_complex_explain'],

	"CONFIRM_ENABLE" => $confirm_yes,
	"CONFIRM_DISABLE" => $confirm_no,
	"COMPLEX_CONFIRM_ENABLE" => $complex_confirm_yes,
	"COMPLEX_CONFIRM_DISABLE" => $complex_confirm_no,

	'L_AKISMET' => $lang['akismet'],
	'L_AKISMET_ENABLE' => $lang['akismet_enable'],
	'L_AKISMET_EXPLAIN' => $lang['akismet_explain'],
	'L_AKISMET_KEY' => $lang['akismet_key'],
	'AKISMET_ENABLE_YES' => $akismet_enable_yes,
	'AKISMET_ENABLE_NO' => $akismet_enable_no,
	'AKISMET_KEY' => $new['akismet_key'],
	'AKISMET_KEY_VALID' => $akismet_key_valid,

	'L_AKISMET_SPAM_COUNTER' => $lang['akismet_spam_counter'],
	'L_AKISMET_SPAM_COUNTER_EXPLAIN' => $lang['akismet_spam_counter_explain'],
	'AKISMET_SPAM_COUNTER' => $new['akismet_counter'],

	"L_ENABLED" => $lang['Enabled'],
	"L_DISABLED" => $lang['Disabled'],
	"L_YES" => $lang['Yes'],
	"L_NO" => $lang['No'],
	"L_SUBMIT" => $lang['Submit'],
	"L_RESET" => $lang['Reset'],

	)
);

$template->pparse('body');

page_footer_admin();

?>